#ifndef _HJ212_REQUEST_H
#define _HJ212_REQUEST_H

#include "hj212_client_def.h"

enum request_response
{
    REQUEST_RESPONSE_ACCEPT = 1,          // 准备执行请求
    REQUEST_RESPONSE_REPULSE = 2,         // 请求被拒绝
    REQUEST_RESPONSE_PW_ERROR = 3,        // PW 错误
    REQUEST_RESPONSE_MN_ERROR = 4,        // MN 错误
    REQUEST_RESPONSE_ST_ERROR = 5,        // ST 错误
    REQUEST_RESPONSE_FLAG_ERROR = 6,      // Flag 错误
    REQUEST_RESPONSE_QN_ERROR = 7,        // QN 错误
    REQUEST_RESPONSE_CN_ERROR = 8,        // CN 错误
    REQUEST_RESPONSE_CRC_ERROR = 9,       // CRC 校验错误
    REQUEST_RESPONSE_UNKNOWN_ERROR = 100, // 未知错误
};

enum request_exe_result
{
    REQUEST_EXE_RESULT_SUCCEED = 1,       // 执行成功
    REQUEST_EXE_RESULT_UNKNOWN_ERROR = 2, // 未知失败原因
    REQUEST_EXE_RESULT_INVALID_PARAM = 3, // 无效参数
    REQUEST_EXE_RESULT_TIMEOUT = 4,       // 通讯超时
    REQUEST_EXE_RESULT_BUZY = 5,          // 系统繁忙
    REQUEST_EXE_RESULT_FAULT = 6,         // 系统故障
    REQUEST_EXE_RESULT_NODATA = 100,      // 无数据
};

int hj212_request_parse(struct hj212_client *client, struct hj212_generalmsg *msg, uint32_t package_state);
void hj212_request_handle(struct hj212_client *client, struct hj212_request *request);

void hj212_request_init(struct hj212_request *request,
                        const char *qn,
                        request_handle_t handle,
                        struct hj212_client *client);
                        
void hj212_request_destroy(struct hj212_request *request);

int hj212_send_request_response(struct hj212_client *client, enum request_response respcode, const char *qn);
int hj212_send_request_exe_result(struct hj212_client *client, enum request_exe_result respcode, const char *qn);

enum request_response hj212_check_request_msg(struct hj212_client *client,
                                              struct hj212_generalmsg *msg,
                                              uint32_t package_state);

int hj212_standard_request_preprocessing(struct hj212_client *client, struct hj212_generalmsg *msg, uint32_t package_state, int cn);

#endif
